﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Http;
using System.Web.Http;
using System.Net.Http.Formatting;
using vncom;
using vncom.Models;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;

namespace vncom.Controllers
{
    public class ApiCategoryController : ApiController
    {
        //
        // GET: /ApiCategory/
        [HttpGet]
        public HttpResponseMessage ApiCategoryAdd(string id, string name)
        {
            string domainName = DataProvider.getDomain(Membership.GetUser().UserName);
            if (domainName != "")
            {
                var Pram = setPram("", name, id, domainName);
                DataProvider.SelectStoreProcedure("DM_SanPhamUser_Ins", Pram);
            }
            return new HttpResponseMessage() { Content = new StringContent("Thành công") };
        }

       [HttpGet]
        public HttpResponseMessage ApiCategoryUpdate(string id, string name)
        {
            var Pram = setPram(id, name, "", "");
            DataProvider.SelectStoreProcedure("DM_SanPhamUser_Upd", Pram);
            return new HttpResponseMessage(){Content = new StringContent("Thành công")};
        }

       [HttpGet]
       public HttpResponseMessage ApiCategoryDel(string id)
       {
           var Pram = setPram(id, "", "", "");
           DataProvider.SelectStoreProcedure("DM_SanPhamUser_Del", Pram);
           return new HttpResponseMessage() { Content = new StringContent("Thành công") };
       }

       public List<SqlParameter> setPram(string _DanhMucSanPhamID = "", string _TenDanhMuc = "", string _ParentID = "", string _Domain = "")
       {
           List<SqlParameter> Pram = new List<SqlParameter>();
           if (_DanhMucSanPhamID != "")
           {
               SqlParameter DanhMucSanPhamID = new SqlParameter("@DanhMucSanPhamID", SqlDbType.Int);
               DanhMucSanPhamID.Value = _DanhMucSanPhamID;
               Pram.Add(DanhMucSanPhamID);
           }
           if (_TenDanhMuc != "")
           {
               SqlParameter TenDanhMuc = new SqlParameter("@TenDanhMuc", SqlDbType.NVarChar);
               TenDanhMuc.Value = _TenDanhMuc;
               Pram.Add(TenDanhMuc);
           }
           if (_ParentID != "")
           {
               SqlParameter ParentID = new SqlParameter("@ParentID", SqlDbType.Int);
               ParentID.Value = _ParentID;
               Pram.Add(ParentID);
           }
           if (_Domain != "")
           {
                SqlParameter Domain = new SqlParameter("@Domain", SqlDbType.VarChar);
                Domain.Value = _Domain;
                Pram.Add(Domain);
           }
           return Pram;
       }
    }
}
